package com.lebang.service.rouseday;

import com.lebang.domain.RouseCountConfig;
import com.lebang.domain.RouseCountMemberRecord;
import com.lebang.example.RouseCountConfigExample;
import com.lebang.mapper.RouseCountMemberRecordMapper;
import com.lebang.model.Whether;
import com.lebang.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
* rouse_count_config
* @Author hwq
* @Date 2020-06-11
*/
@Service
public class RouseCountConfigService extends BaseService<RouseCountConfig,Integer, RouseCountConfigExample>{

      @Autowired
      private RouseCountMemberRecordMapper countRecordMapper;

    /**
     * 获取每日阀值的配置。
     * @return
     */
    public List<RouseCountConfig> selectConfigList() {
        RouseCountConfigExample example=new RouseCountConfigExample();
        example.setOrderByClause("count asc");
        example.createCriteria().andEnableEqualTo(Whether.YES.getDbIndex()).andHasDeletedEqualTo(Whether.NO.getDbIndex());
        return this.selectByExample(example);
    }

    /**
     * 验证是否做过今天是每日阈值任务
     * @param memberId
     * @param rouseConfigId
     * @return
     */
    public RouseCountMemberRecord checkConfigByMemberId(String memberId, Integer rouseConfigId) {
        LocalDate now= LocalDate.now();
        return countRecordMapper.selectRecordByMemberIdAndConfigId(memberId,rouseConfigId,now);
    }

    public RouseCountMemberRecord selectByRecordId(Integer recordId) {
        return countRecordMapper.selectByPrimaryKey(recordId);
    }

    /**
     * 获取今天可以申请的快速提现
     * @param memberId
     * @return
     */
    public List<RouseCountMemberRecord> selectWaitCashList(String memberId) {
        LocalDate now = LocalDate.now();
        LocalDateTime star=LocalDateTime.of(now, LocalTime.MIN);
        LocalDateTime end=LocalDateTime.of(now, LocalTime.MAX);
        return countRecordMapper.selectByTimeAnMemberId(star,end,memberId);

    }

    /**
     * 修改领取状态
     * @param record
     */
    public void updateRecord(RouseCountMemberRecord record) {
        countRecordMapper.updateByPrimaryKeySelective(record);
    }


}
